package com.globallogic.token;

import java.util.List;
import com.globallogic.inout.Out;

public class TokenHandlerHelp implements TokenHandler {

	@Override
	public void execute(TokenProcessor tokenProcessor, List<String> params) {

		TokenProcessor root = tokenProcessor.getParentTokenProcessor();

		Out.printLn("Avalible commands are:");
		
		showHelpForToken(-1, root);
        
		Out.printLn("exit - to exit");

	}
	
	private void showHelpForToken(int level, TokenProcessor tokenProcessor) {

		level++;
		
		for (TokenProcessor element : tokenProcessor){

			for (int i = 0; i < level; i++) {
				Out.printLn("    ");
			}
            
			Out.printLn(element.getHelpString());
        	
        	if (element.getChildCount() > 0) {
        	 
        		showHelpForToken(level, element);
        		
        	}    
        }
		
	}
}
